﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PrismEventAggregator;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow(IEventAggregator eventAggregator)
    {
        InitializeComponent();

        // 1、获取消息对象，通过注入的方式获取
        // 2、通过消息对象进行订阅或者发布
        // 总线 事件对象
        //eventAggregator.GetEvent<EventMessage>().Subscribe(Receive);

        // 1、消息无过滤
        //Messenger.Default.GetEvent<EventMessageArgs>().Subscribe(Receive);

        //eventAggregator.GetEvent<EventMessage>().Publish();
        //Messenger.Default.GetEvent<EventMessageArgs>().Publish(new EventAction()
        //{           
        //    ResultAction = new Action<object>(state => {
        //    })
        //});

        // 2、符合条件的消息接收
        Messenger.Default.GetEvent<EventMessageArgs>().Subscribe(Receive, obj=>obj.ToString() == "11");

        // 3、消息委托的引用方式
        Messenger.Default.GetEvent<EventMessageArgs>().Subscribe(Receive, true);

        // 4、多线程状态控制
        Messenger.Default.GetEvent<EventMessageArgs>().Subscribe(Receive,Prism.Events.ThreadOption.BackgroundThread);
    }

    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);

        Messenger.Default.GetEvent<EventMessageArgs>().Unsubscribe(Receive);
    }
    private void Receive() { 

    }
    private void Receive(object obj) { 

    }
}